package cn.edu360;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import cn.edu360.bean.Request;
import cn.edu360.bean.Response;
import cn.edu360.bean.UserBean;

public class Client {

public static void main(String[] args) {
	 try {
		Socket socket = new Socket("localhost",8888);
		//得到输出流
		ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
		//封装参数
		UserBean bean = new UserBean();
		bean.set(0,"peiqi", "xiaozhu",0,null);
		Request request = new Request();
		request.setClassName("cn.edu360.dao.impl.UserServiceImpl");
		request.setMethodName("login");
		request.setClassType(new Class[]{UserBean.class});
		request.setValue(new Object [] {bean});
		
		//发送数据给Server
		oos.writeObject(request);
		oos.flush();
		
		//接受服务端返回的信息
		ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
		Response res = (Response) ois.readObject();
		System.out.println(res);
		
		//释放资源
		socket.shutdownOutput();
		socket.shutdownInput();
	} catch (Exception e) {
		e.printStackTrace();
	} 
	 
}
}
